/************************************
*  Copyright (C) 2010 Julien MOTTIN.
*  Contact: julien.mottin@gueydan.eu
*
*  This file is part of Gueydan.
*
*  Gueydan is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  Gueydan is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with Gueydan.  If not, see <http://www.gnu.org/licenses/>.
*
*************************************/
#ifndef DURATION_H
#define DURATION_H

// Duration coeffs constants
const static double DCoeffMinute    = 1.0;
const static double DCoeffHour      = 60.0;
const static double DCoeffDay       = 1440.0;
const static double DCoeffWeek      = 10080.0;
const static double DCoeffSecond    = 0.0166666667;


// Handled Unit
enum DurationUnit
{
    Minute = 0,
    Hour,
    Day,
    Week,
    Second
};

class QString;

class Duration
{
public:

    // Standard POD Class
    Duration(const double iDuration = 0.0, const DurationUnit iUnit=Minute);
    Duration(const Duration &iD);
    Duration & operator=(const Duration &iD);
    ~Duration();

    // Operators
    bool operator==(const Duration &iD) const;
    bool operator!=(const Duration &iD) const;
    const Duration operator+(const Duration &iD) const;
    const Duration operator-(const Duration &iD) const;
    bool operator<(const Duration &iD) const;
    bool operator<=(const Duration &iD) const;
    bool operator>(const Duration &iD) const;
    bool operator>=(const Duration &iD) const;

    // Converter
    double Value(const DurationUnit iUnit=Minute) const;
    void FromString(const QString &iString, bool *OK=0);

private:

    double Compare(const Duration &iV) const;

    // Internal data
    double _Value;  // in Minute
};

#endif // DURATION_H
